/**
 * Created by c.y on 2018-1-23
 * 文件说明: 分销渠道修改产品的提交的数据
 */

import prodData from './prodData';
import updateExactComponent from './updateExactData';

/**
* 返回 分销渠道修改产品的提交的数据
 * @param { Object} initialProdInfo 初始化产品
 * @param { Object} updateProdInfo 用户编辑产品的数据对象
 * @return { Object} 提交到后台的数据对象
 */
function getSubmitInfo (initialProdInfo, updateProdInfo) {
    let submitInfo = {
        // 产品基本信息
        prodBaseInfo: {
            prodId: initialProdInfo.prodBaseInfo.prodId
        },
        // 产品列表信息
        prodListItemInfo: {
            id: initialProdInfo.prodListItemInfo.id,
            name: updateProdInfo.prodName,
            tempId: initialProdInfo.prodListItemInfo.tempId,
            isModule: initialProdInfo.prodListItemInfo.isModule,
            type: initialProdInfo.prodListItemInfo.type,
            showEles: prodData.updateProdListElement(initialProdInfo, updateProdInfo)
        },
        // 产品详情信息
        prodDetailInfo: {
            id: initialProdInfo.prodDetailInfo.id,
            name: updateProdInfo.prodName,
            tempId: initialProdInfo.prodDetailInfo.tempId,
            type: initialProdInfo.prodDetailInfo.type,
            isPage: initialProdInfo.prodDetailInfo.isPage,
            isModule: initialProdInfo.prodDetailInfo.isModule,
            unit: {
                prodId: updateProdInfo.prodId,
                prodName: updateProdInfo.prodName,
                prodType: updateProdInfo.prodType
            },
            // 这里是个组件数组,第一个组件类型为2,后面组件类型除了一个4以外全是3
            components: [
                {
                    id: initialProdInfo.prodDetailInfo.components[0].id,
                    name: updateProdInfo.prodName,
                    tempId: initialProdInfo.prodDetailInfo.components[0].tempId,
                    type: initialProdInfo.prodDetailInfo.components[0].type,
                    isModule: initialProdInfo.prodDetailInfo.components[0].isModule,
                    showEles: prodData.updateProdDetailHeadElement(initialProdInfo, updateProdInfo)
                },
                {
                    id: initialProdInfo.prodDetailInfo.components[1].id,
                    name: updateProdInfo.rate,
                    tempId: initialProdInfo.prodDetailInfo.components[1].tempId,
                    type: initialProdInfo.prodDetailInfo.components[1].type,
                    isModule: initialProdInfo.prodDetailInfo.components[1].isModule,
                    showEles: prodData.updateProdDetailContentElement(initialProdInfo, 1, updateProdInfo.rateExample)
                },
                {
                    id: initialProdInfo.prodDetailInfo.components[2].id,
                    name: updateProdInfo.applyCond,
                    tempId: initialProdInfo.prodDetailInfo.components[2].tempId,
                    type: initialProdInfo.prodDetailInfo.components[2].type,
                    isModule: initialProdInfo.prodDetailInfo.components[2].isModule,
                    showEles: prodData.updateProdDetailContentElement(initialProdInfo, 2, updateProdInfo.applyCondCtn)
                },
                // 进件流程
                {
                    id: updateProdInfo.processId,
                    type: 4
                },
                {
                    id: initialProdInfo.prodDetailInfo.components[4].id,
                    name: updateProdInfo.material,
                    tempId: initialProdInfo.prodDetailInfo.components[4].tempId,
                    type: initialProdInfo.prodDetailInfo.components[4].type,
                    isModule: initialProdInfo.prodDetailInfo.components[4].isModule,
                    showEles: prodData.updateProdDetailContentElement(initialProdInfo, 4, updateProdInfo.materialCtn)
                }
            ]
        }
    };
    return updateExactComponent(initialProdInfo, updateProdInfo, submitInfo);
}

export default getSubmitInfo;
